welcome back so in this tutorial we are going to learn a very important concept that is scaling so when we do the preprocessing of our data when the data has naturally the range of their values for example for the age we may have the age go 0-150 150 but for the income we may have even negative income or to positive income like from one to one billion dollars etc so their range is significantly different if we do not scale them nicely it is hard for us to compare them it's because to do a meaningful comparison to know the similarity and the differences we want to know exactly how this data points how this value in terms of their scale in terms of their distribution for example if we know 100 in terms of age is really really a large number but 100 in terms of income as one year it will be super super low so how we can make this super large number 100 and a super low number 100 to be comparable the answer will be scaling that is we are going to scale them into one system so that we can do the comparison the other example will be if you are applying for a graduate school then you will have a different system of GPA if you live in multiple different country some country will have the GPA system as 10 points the maximum will be 10 some country will be 5 some country will be 4 so it will be unfair to compare a 4/4 with another 4/10 even though they are all representing the same 4 but these two 4s are not comparable at all so we have to make the scaling consistent to do the conversion either convert all of them into one system or converts all the others into one of them, like 0-4 in the States so let's get to the setup and we are going to still use our Numpy and the pandas and we are going to use our dataset again our california housing train so you can go to the file you go to the sample and then you choose the trans CSV and copy the path and the paste it here this has been done by thousands of times I believe you will be super comfortable with this dataset now and for this tutorial we are going to know how to do the Mimax scanning that is also called a range mapping scaling and also a Z score standardization which also called remove the mean and compare with the standard deviation the last one is decimal scaling so we are going to cover these three okay so we are going to work on the population as you can see we have the minimum as 3 and the maximum as around 35,000 basically that is a really really large range and we have something mean and standard deviation calculated as well simply because we have 17,000 of records okay so let's look at our MinMax Scalar Scaling this one is just to simply try to mapping all your dataset from your original value which will be your vi and your original minimum which will be here 3 and your original max and original minimum so this fraction basically shows what will be your system of your value in terms of the range and in terms of your particular value then we are going to take in the new system the new system will have a max' and a min' so we are going to use this one as the new range to know that what is your position while in the the old system in terms of the new system so we are going to use the plus min' so that we can get the relative distance from the lower bound of your particular value then the vi' will be the converted will be the scaled value of your particular vi so that will be a very simple formula and if we want to make it simpler like in our real life for the minimum and the maximum scaler scaling we are going to use 0 and 1 as in the new system if we use this one you can see that max' will be 1 min' will be 0 basically these parentheses will be 1 then you can remove it and for the min' will be 0 this will be eliminated as well so if you use 0 and 1 which is also called the normalization because you are going to map all the value into the range of 0 and 1 and the formula will be very simple that is basically we are going to only consider the distance between you as a value to the minimum value in terms of your range so that will be a scaling let's look into this example if we are going to do that for our population so our new column called population_MinMax will be actually converting this formula into the elementwise dataframe manipulation so our population will be minus with the population minimum and the result will be divided by the range which is max - minimum and the result as you can see is like this and if we use the describe now you can see the minimum will be 0 maximum will be 1 and all the data will be following in this 0 to 1 as the new scale so this MinMax scaling is very common in the practice as well as the other one it is called Z score normalization or standardization for this one we are going to use a different strategy and theory background so basically if we are using Z score we also call it as removing the mean because we don't care about the range but we do care about the difference how far this data point is away from your mean regarding standard deviation so with this kind of relative scale we are going to know that how typical this data point is in this particular system so the formula as we can see it is right here your data point will be - mean and then divided by your standard deviation for the example we are still going to play with the population and we are going to name it as a new column population_Z and this new column is calculated based on exactly this formula and the result as we can see here is actually different from the MinMax because depends on a particular dataset you may have the min and the max be any number they will not be 0 and 1 because you don't know what is the min how far this one is away in terms of std toward the mean and how far the max is away from the mean also in terms of std and the interesting fact here is that because we learned before 3 standard deviation from the mean is actually really rare so in this dataset as you can see here the minimum is within 1.24 and the maximum is within 2.98 so basically if we only care about the 3 std away from the mean for outliers then the population definitely has no outliers at all for the decimal scaling we just want to convert all the value into (-1, 1) and so that we know that we have this very limited range and then we can convert them nicely as well so the strategy for this decimal scaling is that we are going to first find out the maximum number in terms of absolute value so it may be the max maybe the minimum because if the absolute value of the minimum is bigger than the absolute value of max then we may choose the minimum value as well basically we want to know what is the largest digits representation of your data and for example if we have a dataset range from -1234 to 999 so basically the maximum absolute value is 1234 and then we need 4 digits to describe or to represent your numbers then we are going to need a t as 4+1 which is 5 basically using 10 to the power of 5 can make sure the converging scale will fall into (-1, 1) let's look into this example for the population we learned that we have some max which is 35,000 so for this one we need to use 5 digits to represent this number so in this case our t will be 6 that is why we have this 10 to the power of 6 in this calculation and then the population decimal will simply be a column with all kinds of float points in this case because the population will not be negative so we are going to end up all everything as positive but below 1 let's describe it our minimum as you can see is really really really small as 0.0000 30 and our maximum is the one (original max) divided by 10^6 because that is our original max number so this one will make sure that you don't have any number any value before the decimal point everything will be after it and I prepared a summary to compare the different scaling strategies so this is our population with original value with the min and the max this will be our MinMax scaling with the min and the max value as well this populationZ is working with the standard deviation mean and standard deviation here so we can see it from this place and then the population decimal is summarized in this place okay so that will be our scaling and hope you enjoyed this tutorial and I will see you later on